var imgClip;
var imgPath;
var imgRange;

function init()
{
	mlf.mcmanager.MessageAgent.getMessageDispatcher().dispatch({type:"onCoverProgress", param:"Init "+this._name+" ..."});
	
	imgClip=Packages.system.mlf.GateKeeper.scanElement(this._name, "imgClip");

	var imgPath_tf=Packages.system.mlf.GateKeeper.scanElement(this._name, "imgPath");
	imgPath=imgPath_tf.text;

	var imgRange_tf=Packages.system.mlf.GateKeeper.scanElement(this._name, "imgRange");
	imgRange=Number(imgRange_tf.text);

	invokeInitComplete();
}

function invokeInitComplete()
{
	loadInitCount=0;
	var smcInstance=mlf.mcmanager.SMCManager.getInstance(this._name);
	smcInstance.addEventListener("onLoadInit", this);
}

function onLoadInit(evt)
{	
	Packages.components.SceneAgent.checkBasicViewCount();
	var smcInstance=mlf.mcmanager.SMCManager.getInstance(this._name);
	smcInstance.removeEventListener("onLoadInit", this);
	refresh();
}

function refresh()
{
	if (imgClip==null) return;
	imgClip.img.removeMovieClip();
	
	var selectedSeq=Math.floor(Math.random()*imgRange);

	var mclListener=new Object();
	mclListener.onLoadInit=function(target_mc:MovieClip)
	{
		target_mc._x=imgClip._width-target_mc._width;
		target_mc._y=imgClip._height-target_mc._height;
		target_mc._alpha=50;

		// add one transition effect
		Packages.system.render.Transition.photoType1(target_mc);
	}
	
	mlf.mcmanager.dynamicloading.LoadApp.loadAppLoader(imgPath+"img"+selectedSeq+".png", imgClip, "img", mclListener);
}